/**
 * 用于手动选择显示的列
 * 这个js文件使用时要引在自己写的代码面，其中使用到的columns要定义成全局静态变量，例var columns = ['user_ID,ID','number,编号','username,用户名','name,姓名','role_NAME,职位','email,邮箱','last_LOGIN,最近登录','ip,上次登录IP'];
 */
function showColumDiv(){
	var bodyobj = document.getElementsByTagName("body");
	if(document.getElementById("columnField")){
		if($("#columnField").is(':visible') == true){
			$("#columnField").hide();
		}else{
			$("#columnField").show();
		}
	}else{
		var divFix = document.createElement("div");
		divFix.setAttribute("style", "width:18px;height:300px;z-index:10000;background-color:white;position:absolute;top:0px");
		var columnDiv = document.createElement("div");
		columnDiv.setAttribute("class","columnDiv");
		columnDiv.setAttribute("id", "columnField");
		var htmlContent = '<div class="control-group"><label class="control-label" style="margin-left:18px;">请选择:</label><div class="controls">';
		for(var i=1;i<columns.length;i++){
			htmlContent += '<label><input checked="true" type="checkbox" onchange="changeColum(this);"/><span class="lbl"><a style="display:none">'+ columns[i].split(',')[0]+'</a></span><span>'+columns[i].split(',')[1]+'</span></label>';
		}
		htmlContent += '</div></div>';
		var closeDiv = '<a href="javascript:closeDiv();" style="position:relative;margin-left:18px;">关闭</a>';
		$(columnDiv).append(htmlContent);
		$(columnDiv).append(closeDiv);
		columnDiv.appendChild(divFix);
		bodyobj[0].appendChild(columnDiv);
	}
}

function closeDiv(){
	if(document.getElementById("columnField")){
		if($("#columnField").is(':visible') == true){
			$("#columnField").hide();
		}else{
			$("#columnField").show();
		}
	}
}
		
function changeColum(obj){
	var flag = obj.checked;
	var columnField = obj.nextElementSibling.firstChild.innerHTML;
	if(flag){
		$("#userTable").bootstrapTable('showColumn',columnField);
	}else{
		$("#userTable").bootstrapTable('hideColumn',columnField);
	}
}
